﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>


<asp:Content ID="OpTitle" ContentPlaceHolderID="TitleContent" runat="server">
	Пульт Оператора 
</asp:Content>

<asp:Content ID="OpBody" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        $(function () {
            //setInterval("GetCall()", 5000);
            //alert("on load");
            GetCall();
        });
        /*$("body").focus(function () {
            alert("khvgsjgfjksdgfjhsdg");
            GetCall();
        });*/
        function GetCall() {
            setTimeout("GetCall()", 5000);
            $.post("/Server/GetCall/", null, GetCallback, "json");
            //alert("getcall");
        }
        function GetCallback(data) {
            if (data != "") {
                var html = "";
                $.each(data, function () {
                    var temp = "<div class=\"client\" id=\"" + this.id + "\">" +
                    "<div class=\"info\"><p>" + this.mess + "</p><p>" + this.id + "</p></div>" +
                    "<div><input type=\"button\" value=\"Принять\" onclick=\"Accept('" + this.id + "')\" />" +
                    "<input type=\"button\" value=\"Отклонить\" onclick=\"Reject('" + this.id + "')\" /></div>" +
                    "</div>";
                    html += temp;
                    //alert(this.mess);
                });
                $("#calls").html(html);
            }
            else { $("#calls").html("<p>На данный момент вызовов нет</p>"); }
            //alert("callback");
        }
        function Accept(id) {
            $.post("/Server/Accept/", { id: id }, AcceptCallback, "json");

        }
        function AcceptCallback(data) {
            if(data.res)
            {
                var url = "/Server/Operator_chat/" + data.c_id;
                window.open(url, 'Оператор', 'width=400, height=300, scrollbars=no,menubar=no,resizable=0,location=no, status=1');
                //GetCall();
            }
        }
        function Reject(id) {
            $.post("/Server/Reject/", { id: id }, null, "json");
            $("#" + id).css("display", "none");
        }
        
    </script>
    <h2>Пульт оператора <%= Html.Encode(ViewData["title"]) %></h2>
    
    <div id="calls">
        
    </div>
        
</asp:Content>

<asp:Content ID="OpHeader" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
